<?php

namespace App\Http\Controllers\Admin;

use App\Constant\Constant;
use App\Models\AdminMenu;

/**
 * 管理平台
 * Class IndexController
 * @package App\Http\Controllers\Admin
 */
class IndexController extends CommonController
{
    // 主页
    public function index()
    {
        return view('admin.index');
    }


    /**
     * 菜单
     * @return \Illuminate\Http\JsonResponse
     * @name:menus
     * @author: lisa
     * @datetime: 2021/10/12 15:24
     */
    public function menus()
    {
        $admin = admin(true)->admin();
        $role  = $admin->role;
        $list  = AdminMenu::whereType(Constant::MenuType_Default)
            ->where(function ($query) use ($role) {
                if (!$role->is_super) {
                    $query->whereIn('id', $role->menu_ids);
                }
            })
            ->orderBy('level', 'asc')
            ->orderBy('sort', 'asc')
            ->get();
        $data  = [];
        foreach ($list as $k => $v) {
            $code   = ($v->menu_no);
            $data[] = [
                'id'       => $v->id,
                'pid'      => $v->pid,
                'level'    => $v->level,
                'title'    => $v->name,
                'icon'     => $v->icon ? "layui-icon {$v->icon}" : "",
                'type'     => $v->is_win,
                'openType' => "_iframe",
                'href'     => $v->uri ? $v->uri . '?code=' . $code : '',
                'menu_no'  => $v->menu_no,
            ];
        }
        $dataTree = array_to_tree($data, 'id', 'pid', 'children', 0);
        return response()->json($dataTree);
    }

    /**
     * 消息
     * @return \Illuminate\Http\JsonResponse
     * @name:messages
     * @author: lisa
     * @datetime: 2021/10/12 16:05
     */
    public function messages()
    {
        $data = [];
        return response()->json($data);
    }

    /**
     * 配置
     * @return \Illuminate\Http\JsonResponse
     * @name:configs
     * @author: lisa
     * @datetime: 2021/10/12 16:07
     */
    public function configs()
    {
        $data = [
            'logo'   => [
                'title' => config('common.admin_name'),
                'image' => '/pearAdmin/admin/images/logo.png'
            ],
            'menu'   => [
                'data'      => '/admin/menus',
                'collaspe'  => false,
                'accordion' => true,
                'method'    => 'GET',
                'control'   => false,
                'select'    => 0,
            ],
            'tab'    => [
                'muiltTab'  => true,
                'keepState' => true,
                'tabMax'    => 30,
                'index'     => [
                    'id'    => 0,
                    'href'  => '/pearAdmin/view/console/index.html',
                    'title' => '首页'
                ]
            ],
            "theme"  => [
                "defaultColor"  => "2",
                "defaultMenu"   => "dark-theme",
                "allowCustom"   => true,
                "defaultHeader" => "light-theme",
                "banner"        => false,
            ],
            "colors" => [
                [
                    "id"     => "1",
                    "color"  => "#2d8cf0",
                    "second" => "#ecf5ff"
                ],
                [
                    "id"     => "2",
                    "color"  => "#36b368",
                    "second" => "#f0f9eb"
                ],
                [
                    "id"     => "3",
                    "color"  => "#f6ad55",
                    "second" => "#fdf6ec"
                ],
                [
                    "id"     => "4",
                    "color"  => "#f56c6c",
                    "second" => "#fef0f0"
                ],
                [
                    "id"     => "5",
                    "color"  => "#3963bc",
                    "second" => "#ecf5ff"
                ]
            ],
            "other"  => [
                "keepLoad" => 1200,
                "autoHead" => false
            ],
            "header" => [
//                "message" => "admin/data/message.json",
            ]
        ];
        return response()->json($data);
    }
}
